﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.Services;
using System.Data;
using System.Collections;


namespace DataServices
{
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]

    public class Services_BSC_OTC : System.Web.Services.WebService
    {
        #region khai bao bien
        DataServices.Code.Connect_DataBase _db = new Code.Connect_DataBase();
        #endregion

        [WebMethod]
        public string HelloWorld()
        {
            return "Hello World";
        }

        [WebMethod]
        public bool CheckLogin(string _username, string _password)
        {
            return _db.CheckLogin(_username, _password);
        }

        // Lấy toàn bộ menu left
        [WebMethod]
        public DataTable GetMenuLeft()
        {
            return _db.Return_Datatable("SELECT * FROM TBL_MENU");
        }

        [WebMethod]
        public string GetFormFunction(string _e)
        {
            switch (_e)
            {
                case "TBL_KHACHHANG":
                    return "KH.TBL_KHACHHANG";
                default:
                    break;
            }
            return "";
        }

        // Lấy toàn bộ bảng view
        #region Get View 
        [WebMethod]
        public DataTable GetViewBy_SearchCode(string _searchcode)
        {
            return _db.Return_Datatable("select * from searchfld" +
                                        " where searchcode like '" + _searchcode + "'" +
                                        " order by position");
        }

        [WebMethod]
        public DataTable SearchView_BySQL(string _tablename, string _sql)
        {
            string sql = "select * from " + _tablename + " where 1=1 " + _sql;
            return _db.SearchView_BySQL(sql);
        }

        [WebMethod]
        public DataTable GetFldMasterBy_Objname(string _objName)
        {
            return _db.Return_Datatable("select * from fldmaster" +
                                        " where objname like '" + _objName + "'" +
                                        " order by odrnum");
        }

        [WebMethod]
        public DataTable GetDatatable_BySQL(string _sql)
        {
            return _db.Return_Datatable(_sql);
        }

        [WebMethod]
        public DataTable GetPhepToanBy_SearchCode(string _searchcode)
        {
            return _db.Return_Datatable("select * from searchfld" +
                                        " where searchcode like '" + _searchcode + "'" +
                                        " AND Display like 'Y'" +
                                        " order by position");
        }

        #endregion

        #region them, sua, xoa 

        [WebMethod]
        public string AddNewRow(string _fldname, DataTable _tableValue)
        {
            return _db.AddNewRow(_fldname, _tableValue);
        }

        [WebMethod]
        public string EditRow(string _fldname, DataTable _tableValue, string _ID_ColumnName, string _ID)
        {
            return _db.EditRow(_fldname, _tableValue, _ID_ColumnName,_ID);
        }

        [WebMethod]
        public string DeleteRow(string _formName, string _ID, string _ID_ColumnName)
        {
            return _db.DeleteRow(_formName,_ID, _ID_ColumnName);
        }

        [WebMethod]
        public bool Check_TrungGiaTri(string _value,string _tableName, string _columnName)
        {
            return _db.Check_TrungGiaTri(_value, _tableName, _columnName);
        }
        #endregion
    }
}